package com.design.patterns.list.singleton;

/**
 * 饿汉式，利用枚举来实现.
 * 利用JDK中枚举是单例的特性
 * @author Wangzhiwen
 */
public class SingletonH {
    public static void main(String[] args) {
        Singleton8 instance1 = Singleton8.INSTANCE;
        Singleton8 instance2 = Singleton8.INSTANCE;
        instance1.print();
        instance2.print();
        System.out.println("instance1.hashCode "+instance1.hashCode());
        System.out.println("instance2.hashCode "+instance2.hashCode());
    }
}

enum Singleton8{
    INSTANCE;

    public void print(){
        System.out.println("方法");
    }
}
